package com.xzbd.gef.policy;

import java.util.Objects;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.ComponentEditPolicy;
import org.eclipse.gef.requests.GroupRequest;

import com.xzbd.core.gef.Node;
import com.xzbd.gef.cmd.DeleteCommand;

public class AppDeletePolicy extends ComponentEditPolicy{

	protected Command createDeleteCommand(GroupRequest deleteRequest){
		EditPart host = getHost();
		if(Objects.isNull(host)){
			return null;
		}
		Object model = host.getModel();
		if(Objects.isNull(model)){
			return null;
		}
		Object parentModel = host.getParent().getModel();
		if(Objects.isNull(parentModel)){
			return null;
		}
		
		if(!(model instanceof Node)){
			return null;
		}
		if(!(parentModel instanceof Node)){
			return null;
		}
		
		Node nodeModel = (Node)model;
		Node pNodeModel = (Node)parentModel;
		return new DeleteCommand(nodeModel,pNodeModel);	
		
		
			
	}

}
